/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wiflydemo_reader;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 *
 * @author JaredSmith
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        //The port your computer is listening on
        int port = 8000;

        byte[] buffer = new byte[24];
        byte[] data = new byte[24];
        //create a reusable datagram for the port you are listening to
        DatagramSocket socket = new DatagramSocket(port);
        java.net.InetAddress address = java.net.InetAddress.getLocalHost();
        DatagramPacket in = new DatagramPacket(buffer, buffer.length);
        System.out.println("### hostname/ip " + address); // name and IP address
        System.out.println("### hostname " + address.getHostName()); // name
        System.out.println("### ip " + address.getHostAddress()); // IP address
        System.out.println("### port " + port);

        //Loop to read in a datagram and print its contents
        while(true) {
            try {
                socket.receive(in);
                data = in.getData();
                System.out.print("Light Intensity = ");
                for(int i = 0; i < data.length; i++) {
                    System.out.print((char)data[i]);
                }
                System.out.println();
            } catch(IOException e) {
                
            }
        }
    }

}
